%{
#include <ctype.h>
#include <stdio.h>
#include "common.h"

#define YYSTYPE double /* double type for Yaac stack */

float yyfval;

void yyerror(const char* msg);
%}

%token NUMBER

%left '+' '-'
%left '*' '/'
%right UMINUS
%%

input     : /* empty */
          {
              printf("BISON: input -> \n");
          }
          
          | input line
          {
              printf("BISON: input -> input line\n");
          }
;

line      : '\n'
          {
              printf("BISON: line -> '\\n'\n");
          }
          
          | expr '\n'
          {
              printf("BISON: line -> expr (%g) '\\n'\n", $1);
          }
;

expr      : NUMBER
          {
              printf("BISON: expr (%g) -> NUMBER (%g)\n", $$, $1);
          }
          
          | expr '+' expr
          {
              $$ = $1 + $3;
              printf("BISON: expr (%g) -> expr (%g) '+' expr (%g)\n", $$, $1, $3);
          }
          
          | expr '-' expr  
          {
              $$ = $1 - $3;
              printf("BISON: expr (%g) -> expr (%g) '-' expr (%g)\n", $$, $1, $3);
          }
          
          | expr '/' expr
          {
              $$ = $1 / $3;
              printf("BISON: expr (%g) -> expr (%g) '/' expr (%g)\n", $$, $1, $3);
          }
          | expr '*' expr
          {
              $$ = $1 * $3;
              printf("BISON: expr (%g) -> expr (%g) '*' expr (%g)\n", $$, $1, $3);
          }
          
          | '(' expr ')'
          {
              $$ = $2;
              printf("BISON: expr (%g) -> '(' expr (%g) ')'\n", $$, $2);
          }
;

%%
#include "lex.yy.c"